Skip to content

Make tuple index constexpr-safe; fix Python Protocol import; tighten XLA typings - #328

Closed
Trinkle23897 wants to merge 2 commits into
mainfrom
codex/fix-lint-issues-and-open-pr
Closed

Make tuple index constexpr-safe; fix Python Protocol import; tighten XLA typings#328
Trinkle23897 wants to merge 2 commits into
mainfrom
codex/fix-lint-issues-and-open-pr

Conversation

@Trinkle23897

Copy link
Copy Markdown
Collaborator

Motivation

  • Ensure compile-time computation of a type's index in a tuple is robust and portable across compilers by replacing the previous fold-expression approach.
  • Make the Protocol import deterministic by checking the running Python version instead of relying on a try/except fallback only.
  • Improve type clarity in XLA helper functions to better reflect arbitrary-length spec tuples.

Description

  • Rewrote Index<T, std::tuple<...>> in envpool/core/tuple_utils.h to use a constexpr std::array<bool, ...> scan to compute kValue, added #include <array>, and moved the static_assert to validate the found index.
  • Kept TupleFromVectorImpl overloads intact but consolidated the constexpr indexing logic for clearer behavior and error messages.
  • In envpool/python/protocol.py added import sys and replaced the try/except import of Protocol with a version check that uses typing.Protocol for Python >= 3.8 and typing_extensions.Protocol otherwise.
  • In envpool/python/xla_template.py updated the type annotation for specs to Tuple[Tuple[Any, ...], Tuple[Any, ...]] to reflect variable-length inner tuples and adjusted formatting accordingly.

Testing

  • Built the C++ library and ran the project's automated unit test suite, which completed successfully.
  • Ran Python static type checks and linters on the modified files, which passed without errors.

Codex Task

@Trinkle23897
Trinkle23897 deleted the codex/fix-lint-issues-and-open-pr branch March 22, 2026 17:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant